﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SimpleLogicSystemTest.cs" company="pwasiewicz">
//   pwasiewicz
// </copyright>
// <summary>
//   The simple logic system test.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace LogicSystem.Tests
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>The simple logic system test.</summary>
    [TestClass]
    public class SimpleLogicSystemTest
    {

        /// <summary>
        /// Gets or sets the system simulator.
        /// </summary>
        /// <value>
        /// The system simulator.
        /// </value>
        public LogicSystemSimulator SystemSimulator { get; set; }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        [TestInitialize]
        public void Initialize()
        {
            var factory = new LogicElementsFactory();

            var p1 = factory.CreateWire();
            var p2 = factory.CreateWire();
            var p3 = factory.CreateWire();

            var andGate = factory.CreateGateAnd(p3, p1, p2);

            p1.AddOutputGates(andGate);
            p2.AddOutputGates(andGate);

            this.SystemSimulator = factory.CreateLogicSystemSimulator(p3, p1, p2);
        }

        /// <summary>Checks the simulating time.</summary>
        [TestMethod]
        public void SimulatingTime()
        {
            Assert.AreEqual(5, this.SystemSimulator.Simulate(false, false));
        }


        /// <summary>
        /// Checks the gate returns true.
        /// </summary>
        [TestMethod]
        public void CheckGateReturnsTrue()
        {
            this.SystemSimulator.Simulate(true, true);
            Assert.AreEqual(true, this.SystemSimulator.OutputWire.State);
        }

        /// <summary>
        /// Checks the gate returns false.
        /// </summary>
        [TestMethod]
        public void CheckGateReturnsFalse()
        {
            this.SystemSimulator.Simulate(true, false);
            Assert.AreEqual(false, this.SystemSimulator.OutputWire.State);
        }
    }
}
